package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TaskRewardSet;
import com.ruoyi.system.service.ITaskRewardSetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务奖励配置Controller
 * 
 * @author DEREK
 * @date 2023-05-23
 */
@RestController
@RequestMapping("/system/rewardSet")
public class TaskRewardSetController extends BaseController
{
    @Autowired
    private ITaskRewardSetService taskRewardSetService;

    /**
     * 查询任务奖励配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:rewardSet:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskRewardSet taskRewardSet)
    {
        startPage();
        List<TaskRewardSet> list = taskRewardSetService.selectTaskRewardSetList(taskRewardSet);
        return getDataTable(list);
    }

    /**
     * 导出任务奖励配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:rewardSet:export')")
    @Log(title = "任务奖励配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskRewardSet taskRewardSet)
    {
        List<TaskRewardSet> list = taskRewardSetService.selectTaskRewardSetList(taskRewardSet);
        ExcelUtil<TaskRewardSet> util = new ExcelUtil<TaskRewardSet>(TaskRewardSet.class);
        util.exportExcel(response, list, "任务奖励配置数据");
    }

    /**
     * 获取任务奖励配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rewardSet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(taskRewardSetService.selectTaskRewardSetById(id));
    }

    /**
     * 新增任务奖励配置
     */
    @PreAuthorize("@ss.hasPermi('system:rewardSet:add')")
    @Log(title = "任务奖励配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskRewardSet taskRewardSet)
    {
        return toAjax(taskRewardSetService.insertTaskRewardSet(taskRewardSet));
    }

    /**
     * 修改任务奖励配置
     */
    @PreAuthorize("@ss.hasPermi('system:rewardSet:edit')")
    @Log(title = "任务奖励配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskRewardSet taskRewardSet)
    {
        return toAjax(taskRewardSetService.updateTaskRewardSet(taskRewardSet));
    }

    /**
     * 删除任务奖励配置
     */
    @PreAuthorize("@ss.hasPermi('system:rewardSet:remove')")
    @Log(title = "任务奖励配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(taskRewardSetService.deleteTaskRewardSetByIds(ids));
    }
}
